# Maintainer: Florian Pritz <bluewind@xinu.at>

pkgname=python-ansi2html
_libname=${pkgname/python-/}
pkgver=1.8.0
pkgrel=4
pkgdesc="Convert text with ANSI color codes to HTML"
arch=('any')
url="https://pypi.python.org/pypi/ansi2html"
license=('LGPL3')
depends=(python python-typing-extensions)
makedepends=(python-build python-installer python-wheel python-setuptools python-setuptools-scm)
checkdepends=(python-pytest)
source=(
  "https://files.pythonhosted.org/packages/source/${_libname:0:1}/$_libname/$_libname-$pkgver.tar.gz"
  $pkgname-1.8.0-build_requirements.patch::https://github.com/pycontribs/ansi2html/commit/be9c47dd39e500b2e34e95efde90d0a3b44daaee.patch
)
sha256sums=('38b82a298482a1fa2613f0f9c9beb3db72a8f832eeac58eb2e47bf32cd37f6d5'
            'b0e15052c5c89e5d76c70e25f4bfeef3d18011ff7efba06d4de74148c3dbb62b')
b2sums=('66672927a64ad38dce0b0819fabc3778f6aba82d176e992630a8db076988a21af8dd445306b8bb580f1539b35044b95de749d6bfb65c27f9b431e4cb6bd562c7'
        '66c922bbfc91b6880224e10bce61981eaf40754f0c44e43905091963de740bc265eaa660491e6f923c7a0b2f91e60728169e2e48cbed0b346667fbe522bc7796')
validpgpkeys=(94504C3AE11DD197920058ABA90ED7DE971095FF)

prepare() {
    # drop the use of python-setuptools-scm-git-archive: https://github.com/pycontribs/ansi2html/pull/189
    patch -Np1 -d $_libname-$pkgver -i ../$pkgname-1.8.0-build_requirements.patch
}

build() {
    cd "$_libname-$pkgver"
    python -m build --wheel --no-isolation
}

check() {
    local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

    cd "$_libname-$pkgver"
    python -m installer --destdir=test_dir dist/*.whl
    export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
    export PATH="$PWD/test_dir/usr/bin:$PATH"
    pytest -vv
}

package() {
    cd "$_libname-$pkgver"
    python -m installer --destdir="$pkgdir" dist/*.whl
}
